package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

public class BandSwOsc extends BandTrOsc {

	private Indicator lowBand2;
	private Indicator highBand2;
	
	private Indicator trigger;
	
	public BandSwOsc(String name, DataManager dataManager, Indicator input, Indicator lB, Indicator hB, Indicator lB2, Indicator hB2) {
		super(name, dataManager, input, lB, hB);
		this.lowBand2 = lB2;
		this.highBand2 = hB2;
	}

	@Override
	public double execute(double x) {
		double v = getDataManager().getLast(getInput().getName());
		double lB = getDataManager().getLast(getLowBand().getName());
		double hB = getDataManager().getLast(getHighBand().getName());
		double lB2 = getDataManager().getLast(getLowBand2().getName());
		double hB2 = getDataManager().getLast(getHighBand2().getName());

		if (v < lB || v > hB) {
			return 0;
		}
		
		if (0.5 * lB < v &&  v < 0.5 * hB) {
//			return 0;
		}
		
		if (lB2 < v &&  v < hB2) {
//			return 0;
		}
		
		double down = v - hB;
		double up = v - lB;
		
		if (down < 0 && Math.abs(down) < Math.abs(up)) {
			return down;
		}
		if (up > 0 && Math.abs(up) < Math.abs(down)) {
			return up;
		}
		
		return 0;
	}

	protected Indicator getLowBand2() {
		return lowBand2;
	}

	protected Indicator getHighBand2() {
		return highBand2;
	}

	protected Indicator getTrigger() {
		return trigger;
	}
}
